﻿using Sidvall.UI.Dialogs;
using System.Threading.Tasks;

namespace Sidvall.UI.Wpf.Dialogs
{
    public partial class ProgressDialog
    {
        #region Public Members

        #region ShowAsync

        public Task ShowAsync(ProgressDialogContext context, object owner)
        {
            this.ProgressControl.InitializeContext(context);
            this.Title = context.Title;
            WindowManager.SetWindowOwner(this, owner);
            ShowDialog();
            return Task.FromResult(true);
        }

        #endregion

        #endregion
        #region Events

        #region ProgressControl_CloseSelected

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        private void ProgressControl_CloseSelected(object sender, System.EventArgs e)
        {
            Close();
        }

        #endregion
        #region Window_Activated

        private async void Window_Activated(object sender, System.EventArgs e)
        {
            await this.ProgressControl.StartAsync();
        }

        #endregion
        #region Window_Closing

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.ProgressControl.Stop();
        }

        #endregion

        #endregion
        #region Constructors

        public ProgressDialog()
        {
            InitializeComponent();

            Sidvall.UI.Wpf.ControlManager.SetLanguage(this);
        }

        #endregion
    }
}
